home *** CD-ROM | disk | FTP | other *** search
-
- { graphics initialization unit }
- { released to public domain 3/15/89 by author Michael Day }
-
- unit Gstart;
-
- interface
-
- uses graph;
-
- type rect = record Xmin,Ymin,Xmax,Ymax:integer; end;
-
- const NoDisp = 0;
- CgaDisp = 1;
- HercDisp = 2;
- EgaDisp = 3;
-
- const
- DispType : integer = 0;
- GrMode : integer = 0;
- GrDriver : integer = 0;
- ErrCode : integer = 0;
- BoxTextHeight : integer = 8;
- BoxTextWidth : integer = 8;
- GraphOn : boolean = false;
- ForceCGA : integer = 0; {override for testing}
-
-
- {---------------------------------------}
- {initializes the graphics display}
- {returns true if all went well. Returns false if not}
- {DispType is set to the display type we are working with}
- {or to NoDisp if could not install the display}
-
- function GrafStart:boolean;
-
- {---------------------------------------}
- {turn off graphics mode}
-
- procedure SetGraphOff;
-
- {-----------------------------------------------------------------}
- { Ack! Something very serious happened that we can't recover from }
-
- procedure BombOut(Err:integer);
-
- {---------------------------------------}
-
- implementation
-
- function GrafStart:boolean;
- begin
- GrafStart := false;
- GraphOn := false;
- DispType := NoDisp;
-
- DetectGraph(GrDriver,GrMode);
- Errcode := GraphResult;
- if Errcode = GrOk then
- begin
-
- if ForceCGA <> 0 then GrDriver := ForceCGA; {override for testing}
-
- case GrDriver of
- CGA : begin
- DispType := CgaDisp; {we like CGA (not really, but...)}
- GrMode := CGAhi;
- BoxTextHeight := 8;
- BoxTextWidth := 8;
- end;
- HercMono : begin
- DispType := HercDisp; {and we like Hercules (sort of)}
- GrMode := HercMonohi;
- BoxTextHeight := 12;
- BoxTextWidth := 8;
- end;
- EGA : begin
- DispType := EgaDisp; {and we like EGA}
- GrMode := EGAhi;
- BoxTextHeight := 12;
- BoxTextWidth := 8;
- end;
- EGA64 : begin
- DispType := CgaDisp; {we make ega64 into cga}
- GrMode := EGA64lo;
- BoxTextHeight := 8;
- BoxTextWidth := 8;
- end;
- VGA : begin
- DispType := EgaDisp; {we make VGA into EGA}
- GrMode := VGAmed;
- BoxTextHeight := 12;
- BoxTextWidth := 8;
- end;
- MCGA : begin
- DispType := CgaDisp; {we make MCGA into CGA}
- GrMode := MCGAmed;
- BoxTextHeight := 8;
- BoxTextWidth := 8;
- end;
- ATT400 : begin
- DispType := CgaDisp; {we make ATT400 into CGA}
- GrMode := ATT400med;
- BoxTextHeight := 8;
- BoxTextWidth := 8;
- end;
- else
- CloseGraph; {not a recognized display, so shut it down}
- end;
- end;
-
- if DispType = NoDisp then
- GrafStart := false
- else
-
- begin
- InitGraph(GrDriver,GrMode,'');
- Errcode := GraphResult;
- if Errcode = GrOk then
- begin
- GrafStart := true;
- GraphOn := true;
- end
- else
- begin
- writeln('Graphics error:',grapherrormsg(errcode));
- GrafStart := false;
- GraphOn := false;
- end;
- end;
- end;
-
- {-------------------}
- procedure SetGraphOff;
- begin
- Closegraph;
- GraphOn := false;
- end;
-
- {-------------------}
- procedure BombOut(Err:integer);
-
- function ErrMsg(Err:byte):string;
- var S:string[8];
- begin
- str(Err,S);
- ErrMsg := S;
- end;
-
- begin
- SetGraphOff;
- Writeln(' System error: '+ErrMsg(Err));
- Writeln(' - Unable to continue, program aborted -');
- Halt(Err);
- end;
-
- {-------------------}
- {no unit init needed}
- end.